<?php

namespace HuangYi\Rbac\Models;

use Illuminate\Database\Schema\Blueprint;

trait MigrationHelper
{
    /**
     * Sets primary key.
     *
     * @param \Illuminate\Database\Schema\Blueprint $table
     * @param string $type
     */
    public function primaryKey(Blueprint $table, $type)
    {
        if ($type === 'uuid') {
            $table->uuid('id')->primary();
        } else {
            $table->increments('id');
        }
    }

    /**
     * Sets foreign key.
     *
     * @param \Illuminate\Database\Schema\Blueprint $table
     * @param string $name
     * @param string $type
     */
    public function foreignKey(Blueprint $table, $name, $type)
    {
        if ($type === 'uuid') {
            $table->uuid($name);
        } else {
            $table->unsignedInteger($name);
        }
    }
}
